frappe.ui.form.on('Equipment', {
    refresh: function(frm) {
        if (frm.doc.docstatus === 1) {
            // 生成二维码按钮
            frm.add_custom_button(__('生成二维码'), function() {
                eam.utils.generate_qr_code(frm.doc.equipment_code);
            }, __('操作'));
            
            // 维护记录按钮
            frm.add_custom_button(__('维护记录'), function() {
                eam.utils.show_maintenance_history(frm.doc.name);
            }, __('查看'));
            
            // 创建维护计划按钮
            frm.add_custom_button(__('创建维护计划'), function() {
                frappe.new_doc('Equipment Maintenance Plan', {
                    equipment: frm.doc.name,
                    equipment_name: frm.doc.equipment_name
                });
            }, __('操作'));
        }
    },
    
    equipment_category: function(frm) {
        // 根据设备分类自动填充一些默认值
        if (frm.doc.equipment_category) {
            frappe.db.get_doc('Equipment Category', frm.doc.equipment_category)
                .then(category => {
                    if (category.default_warranty_period) {
                        frm.set_value('warranty_period', category.default_warranty_period);
                    }
                });
        }
    }
});